﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProductSystem.BLL.Common
{
    /// <summary>
    /// 委托形式的比较器
    /// </summary>
    public class DelegateEqualityComparer<T> : IEqualityComparer<T>
    {
        private Func<T, T, bool> equalsFunc = null;
        private Func<T, int> getHashCodeFunc = null;
        public DelegateEqualityComparer(Func<T, T, bool> equalsFunc, Func<T, int> getHashCodeFunc)
        {
            this.equalsFunc = equalsFunc;
            this.getHashCodeFunc = getHashCodeFunc;
        }
        public bool Equals(T x, T y)
        {
            return equalsFunc(x, y);
        }
        public int GetHashCode(T obj)
        {
            return getHashCodeFunc(obj);
        }
    }
}
